package cn.gson.springboot.controller;

import cn.gson.springboot.model.pojos.PaymentPlan;
import cn.gson.springboot.model.service.PaymentPlanService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class PaymentPlanController {
    @Autowired
    PaymentPlanService payPlanService;

    @RequestMapping("/pay-plan-list")
    @ResponseBody
    public Map<String,Object> payPlanList(Integer page,Integer size,Integer type,String payDate){
        Page<Object> objects = PageHelper.startPage(page, size);
        List<PaymentPlan> pay = payPlanService.selectPaymentPlan(type,payDate);
        Map<String,Object> map = new HashMap<>();
        map.put("total",objects.getTotal());
        map.put("rows",pay);
        return map;
    }

    @RequestMapping("/pay-plan-pur-list")
    @ResponseBody
    public List<PaymentPlan> payPlanPurList(Integer purId){
        List<PaymentPlan> pay = payPlanService.selectPaymentPlanByPurId(purId);
        return pay;
    }

    @RequestMapping("/pay-plan")
    @ResponseBody
    public PaymentPlan payPlanPayList(Integer payId){
        PaymentPlan pay = payPlanService.selectPaymentPlanById(payId);
        return pay;
    }

    @RequestMapping("/pay-plan-past-future-thirty-list")
    @ResponseBody
    public List<PaymentPlan> selectPaymentPlanPastFutureThirty(){
        List<PaymentPlan> pay = payPlanService.selectPaymentPlanPastFutureThirty();
        return pay;
    }


    @PostMapping("/save-pay-plan")
    @ResponseBody
    public void savePayPlan(@RequestBody PaymentPlan pay){
         payPlanService.savePaymentPlan(pay);
    }

    @PostMapping("/delete-pay-plan")
    @ResponseBody
    public void deletePayPlan(@RequestParam(value = "payId") Integer payId){
        payPlanService.deletePaymentPlan(payId);
    }
}
